home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / pdevtest / pdevtest.c < prev    next >
C/C++ Source or Header  |  1990-06-28  |  5KB  |  192 lines

  1. /*
  2.  * Driver for the new (Dec 87) pseudo-device implementation.
  3.  *
  4.  * The programs output goes to standard out, while the
  5.  * statistics taken go to error output or another file.
  6.  */
  7.  
  8. #include "sprite.h"
  9. #include "status.h"
  10. #include "stdio.h"
  11. #include "fs.h"
  12. #include "fsCmd.h"
  13. #include "sysStats.h"
  14. #include "rpc.h"
  15. #include "proc.h"
  16. #include "vm.h"
  17. #include "kernel/sched.h"
  18. #include "kernel/fsStat.h"
  19. #include "kernel/vm.h"
  20. #include "option.h"
  21.  
  22. Boolean useSelect = FALSE;
  23. Boolean copy = FALSE;
  24. Boolean readP = FALSE;
  25. Boolean writeP = FALSE;
  26. Boolean ioctlP = FALSE;
  27. Boolean selectP = FALSE;
  28. Boolean zero = FALSE;
  29. Boolean switchBuf = FALSE;
  30. Boolean writeBehind = FALSE;
  31. int requestBufSize = 2048;
  32. int size = 128;
  33. int reps = 10;
  34. int numClients = -1;            /* For multi-program synchronization,
  35.                      * this is the number of slaves with
  36.                      * which to synchronize */
  37. int delay = 0;                /* Delay loop for server to eat CPU */
  38. Boolean slave = FALSE;
  39. extern char *pdev;
  40.  
  41. Option optionArray[] = {
  42.     {OPT_INT, "srvr", (Address)&numClients,
  43.         "Server for -srvr (int) clients"},
  44.     {OPT_TRUE, "clnt", (Address)&slave,
  45.         "Client process"},
  46.     {OPT_INT, "reps", (Address)&reps,
  47.         "Number of repetitions"},
  48.     {OPT_INT, "size", (Address)&size,
  49.         "Amount of data to transfer"},
  50.     {OPT_TRUE, "selectTest", (Address)&selectP,
  51.         "Select, makes server block client"},
  52.     {OPT_TRUE, "fork", (Address)©,
  53.         "Fork client process (with -clnt)"},
  54.     {OPT_TRUE, "read", (Address)&readP,
  55.         "Read test"},
  56.     {OPT_TRUE, "write", (Address)&writeP,
  57.         "Write test"},
  58.     {OPT_TRUE, "writeBehind", (Address)&writeBehind,
  59.         "Enable write behind (with -srvr)"},
  60.     {OPT_TRUE, "ioctl", (Address)&ioctlP,
  61.         "IOControl test"},
  62.     {OPT_INT, "delay", (Address)&delay,
  63.         "Loop for -delay <int> cylces before replying"},
  64.     {OPT_TRUE, "switchBuf", (Address)&switchBuf,
  65.         "Test switching request buffers (use with -ioctl)"},
  66.     {OPT_STRING, "pdev", (Address)&pdev,
  67.         "Name of the pseudo device"},
  68.     {OPT_INT, "bufsize", (Address)&requestBufSize,
  69.         "Size of the pseudo device request buffer"},
  70.     {OPT_TRUE, "forceSelect", (Address)&useSelect,
  71.         "Make Master use select with 1 client"},
  72. };
  73. int numOptions = sizeof(optionArray) / sizeof(Option);
  74.  
  75. Time startTime, endTime;
  76. Sched_Instrument startSchedStats, endSchedStats;
  77.  
  78. main(argc, argv)
  79.     int argc;
  80.     char *argv[];
  81. {
  82.     register ReturnStatus status = SUCCESS;
  83.     Proc_PID child;
  84.     Proc_ResUsage usage;
  85.     FILE *outStream;
  86.     register int i;
  87.     ClientData serverData, clientData;
  88.  
  89.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  90.     if (!slave && (numClients < 0)) {
  91.     fprintf(stderr, "Server: %s [options] -srvr numClients\n",  argv[0]);
  92.     fprintf(stderr, "Client: %s [options] -clnt\n", argv[0]);
  93.     Opt_PrintUsage(argv[0], numOptions, optionArray);
  94.     exit(1);
  95.     }
  96.     /*
  97.      * Check for multi-program master/slave setup.
  98.      */
  99.     if (numClients > 0) {
  100.     ServerSetup(numClients, &serverData);
  101.     slave = FALSE;
  102.     }
  103.     if (slave) {
  104.     ClientSetup(&clientData);
  105.     }
  106.     /*
  107.      * Get first sample of time and idle ticks.
  108.      */
  109.     status = Sys_Stats(SYS_SCHED_STATS, 0, &startSchedStats);
  110.     if (status != SUCCESS) {
  111.     Stat_PrintMsg(status, "Error in Sys_Stats");
  112.     exit(status);
  113.     }
  114.  
  115.     status = Sys_GetTimeOfDay(&startTime, NULL, NULL);
  116.     if (status != SUCCESS) {
  117.     Stat_PrintMsg(status, "Error in Sys_GetTimeOfDay");
  118.     exit(status);
  119.     }
  120.     if (slave) {
  121.     if (copy) {
  122.         status = Proc_Fork(TRUE, &child);
  123.         if (status != PROC_CHILD_PROC && status != SUCCESS) {
  124.         Stat_PrintMsg(status, "Fork failed");
  125.         exit(status);
  126.         }
  127.     }
  128.     if (readP) {
  129.         ClientRead(clientData, size, reps);
  130.     }
  131.     if (writeP) {
  132.         ClientWrite(clientData, size, reps);
  133.     }
  134.     if (ioctlP) {
  135.         ClientIOControl(clientData, size, reps);
  136.     }
  137.     if (copy) {
  138.         if (status != PROC_CHILD_PROC) {
  139.         status = Proc_Wait(0, NULL, TRUE, NULL, NULL, NULL, NULL, &usage);
  140.         } else {
  141.         exit(SUCCESS);
  142.         }
  143.     }
  144.     /*
  145.      * Take ending statistics and print user, system, and elapsed times.
  146.      */
  147.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  148.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  149.     Time_Subtract(endTime, startTime, &endTime);
  150.     printf("Slave (reps = %d) ", reps);
  151.     PrintTimes(stdout, &usage, &endTime);
  152.  
  153.     ClientDone(clientData);
  154.     /*
  155.      * Print FS statistics.
  156.      */
  157.     } else {
  158.     /*
  159.      * Drop into the top level service loop.  ServeOne is a faster
  160.      * version that doesn't use select because there is only
  161.      * one client.
  162.      */
  163.     if (numClients > 1 || useSelect) {
  164.         Serve(serverData);
  165.     } else {
  166.         ServeOne(serverData);
  167.     }
  168.     /*
  169.      * Take ending statistics and print user, system, and elapsed times.
  170.      */
  171.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  172.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  173.     Time_Subtract(endTime, startTime, &endTime);
  174.     printf("Master: ");
  175.     PrintTimes(stdout, &usage, &endTime);
  176.  
  177.     if (delay > 0) {
  178.         int cnt;
  179.         Sys_GetTimeOfDay(&startTime, NULL, NULL);
  180.         for (cnt=0 ; cnt<50 ; cnt++) {
  181.         for (i=delay<<1 ; i>0 ; i--) ;
  182.         }
  183.         Sys_GetTimeOfDay(&endTime, NULL, NULL);
  184.         Time_Subtract(endTime, startTime, &endTime);
  185.         Time_Divide(endTime, 50, &endTime);
  186.         printf("%d.%06d seconds service delay\n",
  187.         endTime.seconds, endTime.microseconds);
  188.     }
  189.     }
  190.     exit(status);
  191. }
  192.